package com.wx.springcloud.controller;

import com.wx.springcloud.entities.CommonResult;
import com.wx.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author wangdada
 */
@RestController
@Slf4j
public class OrderController {
    public static final String PAYMENT_SERVICE_URL = "http://CLOUD-PAYMENT-SERVICE";


    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/consumer/payment/create")
    public CommonResult create(@RequestBody Payment payment) {
        log.info("创建订单：{}" + payment.toString());
        return restTemplate.postForObject(PAYMENT_SERVICE_URL + "/payment/create", payment, CommonResult.class);
    }

    @GetMapping("/comsumer/payment/{id}")
    public CommonResult getPaymentById(@PathVariable Long id) {
        log.info("查询订单id:{}", id);
        return restTemplate.getForObject(PAYMENT_SERVICE_URL + "/payment/" + id, CommonResult.class);
    }
}
